<?php defined('InShopNC') or exit('Access Invalid!'); ?>

<div class="page">
    <div class="fixed-bar">
        <div class="item-title"><a class="back" href="index.php?act=marketing_activity&op=marketing_activity"
                                   title="返回<?php echo $lang['nc_manage']; ?>列表"><i
                        class="fa fa-arrow-circle-o-left"></i></a>
            <div class="subject">
                <h3><?php echo $lang['activity_index_manage']; ?> - <?php echo $lang['nc_edit']; ?>
                    活动“<?php echo $output['marketing_activity']['marketing_activity_title']; ?>”</h3>
                <h5><?php echo $lang['activity_index_manage_subhead']; ?></h5>
            </div>
        </div>
    </div>
    <form id="add_form" method="post" enctype="multipart/form-data">
        <input type="hidden" name="form_submit" value="ok"/>
        <input type="hidden" name="marketing_activity_id"
               value="<?php echo $output['marketing_activity']['marketing_activity_id']; ?>"/>
        <div class="ncap-form-default">
            <dl class="row">
                <dt class="tit">
                    <label for="marketing_activity_title"><em>*</em><?php echo $lang['activity_index_title']; ?></label>
                </dt>
                <dd class="opt">
                    <?php if ($output['if_alter'] === true): ?>
                        <input type="text" id="marketing_activity_title" name="marketing_activity_title"
                               class="input-txt"
                               value="<?php echo $output['marketing_activity']['marketing_activity_title']; ?>">
                    <?php else: ?>
                        <input type="text" id="marketing_activity_title" name="marketing_activity_title"
                               class="input-txt"
                               value="<?php echo $output['marketing_activity']['marketing_activity_title']; ?>"
                               readonly>
                    <?php endif; ?>
                    <span class="err"></span>
                    <p class="notic"></p>
                </dd>
            </dl>
            <dl class="row">
                <dt class="tit">
                    <label><em>*</em><?php echo $lang['activity_index_apply_start']; ?></label>
                </dt>
                <dd class="opt">
                    <?php if ($output['if_alter'] === true): ?>
                        <input type="text" id="marketing_activity_apply_start_date"
                               name="marketing_activity_apply_start_date" class="input-txt"
                               value="<?php echo date('Y-m-d H:i', $output['marketing_activity']['marketing_activity_apply_start_date']); ?>"/>
                    <?php else: ?>
                        <input type="text" id="marketing_activity_apply_start_date"
                               name="marketing_activity_apply_start_date" class="input-txt"
                               value="<?php echo date('Y-m-d H:i', $output['marketing_activity']['marketing_activity_apply_start_date']); ?>"
                               readonly/>
                    <?php endif; ?>
                    <span class="err"></span>
                    <p class="notic"></p>
                </dd>
            </dl>
            <dl class="row">
                <dt class="tit">
                    <label><em>*</em><?php echo $lang['activity_index_apply_end']; ?></label>
                </dt>
                <dd class="opt">
                    <?php if ($output['if_alter'] === true): ?>
                        <input type="text" id="marketing_activity_apply_end_date"
                               name="marketing_activity_apply_end_date" class="input-txt"
                               value="<?php echo date('Y-m-d H:i', $output['marketing_activity']['marketing_activity_apply_end_date']); ?>"/>
                    <?php else: ?>
                        <input type="text" id="marketing_activity_apply_end_date"
                               name="marketing_activity_apply_end_date" class="input-txt"
                               value="<?php echo date('Y-m-d H:i', $output['marketing_activity']['marketing_activity_apply_end_date']); ?>"
                               readonly/>
                    <?php endif; ?>
                    <span class="err"></span>
                    <p class="notic"></p>
                </dd>
            </dl>
            <dl class="row">
                <dt class="tit">
                    <label for="store_goods_limit"><em>*</em><?php echo $lang['activity_store_goods_limit']; ?></label>
                </dt>
                <dd class="opt">
                    <?php if ($output['if_alter'] === true): ?>
                        <input type="text" id="store_goods_limit" name="store_goods_limit" class="input-txt"
                               value="<?= $output['marketing_activity']['store_goods_limit']; ?>"/>
                    <?php else: ?>
                        <input type="text" id="store_goods_limit" name="store_goods_limit" class="input-txt"
                               value="<?= $output['marketing_activity']['store_goods_limit']; ?>" readonly/>
                    <?php endif; ?>
                    <span class="err"></span>
                    <p class="notic"><?php echo $lang['activity_index_help5']; ?></p>
                </dd>
            </dl>

            <?php if($output['marketing_activity']['marketing_activity_type'] == 3 ||  $output['marketing_activity']['marketing_activity_type'] == 4){?>
            <dl class="row">
                <dt class="tit">
                    <label for="min_num"><em>*</em>参团人数(砍价/拼团类型必填)</label>
                </dt>
                <dd class="opt">
                    <?php if ($output['if_alter'] === true): ?>
                    <input type="number" id="min_num" name="min_num" class="input-txt" value="<?= $output['marketing_activity']['min_num']; ?>" min="0">
                    <?php else: ?>
                    <input type="number" id="min_num" name="min_num" class="input-txt" value="<?= $output['marketing_activity']['min_num']; ?>" min="0">
                    <?php endif; ?>
                    <span class="err"></span>
                    <p class="notic">建议设置3到5人，因人数越多成团机率越小</p>
                </dd>
            </dl>
            <?php }?>

            <dl class="row" style="display:block;">
                <dt class="tit">
                    <label><em>*</em><?php echo $lang['activity_index_type']; ?></label>
                </dt>
                <dd class="opt">
                    <?php if ($output['if_alter'] === true): ?>
                        <select name="marketing_activity_type">
                            <optgroup>
                                <?php foreach ($output['marketing_activity_type'] as $k => $v): ?>
                                    <option value="<?= $k ?>" <?= (isset($output['marketing_activity']['marketing_activity_type']) && ($output['marketing_activity']['marketing_activity_type'] == $k)) ? 'selected="selected"' : '' ?> ><?= $v ?></option>
                                <?php endforeach; ?>
                            </optgroup>
                        </select>
                    <?php else: ?>
                        <input type="text" name="marketing_activity_type" class="input-txt"
                               value="<?= $output['marketing_activity_type'][$output['marketing_activity']['marketing_activity_type']]; ?>"
                               readonly/>
                    <?php endif; ?>
                    <span class="err"></span>
                    <p class="notic"><?php echo $lang['activity_new_type_tip']; ?></p>
                </dd>
            </dl>

            <dl class="row">
                <dt class="tit">
                    <label for="marketing_activity_start_date"><em>*</em><?php echo $lang['activity_index_apply_start']; ?>
                    </label>
                </dt>
                <dd class="opt">
                    <?php if ($output['if_alter'] === true): ?>
                        <input type="text" id="marketing_activity_start_date" class="input-txt"
                               name="marketing_activity_start_date"
                               value="<?php echo date('Y-m-d H:i', $output['marketing_activity']['marketing_activity_start_date']); ?>"/>
                    <?php else: ?>
                        <input type="text" id="marketing_activity_start_date" class="input-txt"
                               name="marketing_activity_start_date"
                               value="<?php echo date('Y-m-d H:i', $output['marketing_activity']['marketing_activity_start_date']); ?>"
                               readonly/>
                    <?php endif; ?>
                    <span class="err"></span>
                    <p class="notic"></p>
                </dd>
            </dl>
            <dl class="row">
                <dt class="tit">
                    <label for="marketing_activity_end_date"><em>*</em><?php echo $lang['activity_index_end']; ?>
                    </label>
                </dt>
                <dd class="opt">
                    <?php if ($output['if_alter'] === true): ?>
                        <input type="text" id="marketing_activity_end_date" class="input-txt"
                               name="marketing_activity_end_date"
                               value="<?php if (!empty($output['marketing_activity']['marketing_activity_end_date'])) echo date('Y-m-d H:i', $output['marketing_activity']['marketing_activity_end_date']); ?>"/>
                    <?php else: ?>
                        <input type="text" id="marketing_activity_end_date" class="input-txt"
                               name="marketing_activity_end_date"
                               value="<?php if (!empty($output['marketing_activity']['marketing_activity_end_date'])) echo date('Y-m-d H:i', $output['marketing_activity']['marketing_activity_end_date']); ?>"
                               readonly/>
                    <?php endif; ?>
                    <span class="err"></span>
                    <p class="notic"></p>
                </dd>
            </dl>
            <dl class="row">
                <dt class="tit">
                    <label for="marketing_activity_banner"><em>*</em><?php echo $lang['activity_index_banner']; ?>
                    </label>
                </dt>
                <dd class="opt">
                    <div class="input-file-show">
            <span class="show">
              <a class="nyroModal" rel="gal"
                 href="<?php if (is_file(BASE_UPLOAD_PATH . DS . ATTACH_ACTIVITY . DS . $output['marketing_activity']['marketing_activity_banner'])) {
                     echo UPLOAD_SITE_URL . "/" . ATTACH_ACTIVITY . "/" . $output['marketing_activity']['marketing_activity_banner'];
                 } else {
                     echo ADMIN_SITE_URL . "/templates/" . TPL_NAME . "/images/sale_banner.jpg";
                 } ?>"> <i class="fa fa-picture-o"
                           onMouseOver="toolTip('<img src=<?php if (is_file(BASE_UPLOAD_PATH . DS . ATTACH_ACTIVITY . DS . $output['marketing_activity']['marketing_activity_banner'])) {
                               echo UPLOAD_SITE_URL . "/" . ATTACH_ACTIVITY . "/" . $output['marketing_activity']['marketing_activity_banner'];
                           } else {
                               echo ADMIN_SITE_URL . "/templates/" . TPL_NAME . "/images/sale_banner.jpg";
                           } ?>>')" onMouseOut="toolTip()"></i>
              </a>
            </span>
                        <?php if ($output['if_alter'] === true): ?>
                            <span class="type-file-box">
                <input type="file" class="type-file-file" id="marketing_activity_banner"
                       name="marketing_activity_banner" size="30" hidefocus="true"
                       nc_type="upload_marketing_activity_banner" title="点击前方预览图可查看大图，点击按钮选择文件并提交表单后上传生效">
              </span>
                        <?php endif; ?>
                    </div>
                    <span class="err"></span>
                    <p class="notic"><?php echo $lang['activity_new_banner_tip']; ?></p>
                </dd>
            </dl>
            <dl class="row" style="display:none;">
                <dt class="tit">
                    <label for="marketing_activity_style"><?php echo $lang['marketing_activity_new_style']; ?></label>
                </dt>
                <dd class="opt">
                    <select id="marketing_activity_style" name="marketing_activity_style">
                        <option value="default_style"
                                <?php if ($output['marketing_activity']['marketing_activity_style'] == "default_style"){ ?>selected<?php } ?>><?php echo $lang['activity_index_default']; ?></option>
                    </select>
                    <span class="err"></span>
                    <p class="notic"><?php echo $lang['activity_new_style_tip']; ?></p>
                </dd>
            </dl>
            <dl class="row">
                <dt class="tit">
                    <label for="marketing_activity_desc"><?php echo $lang['activity_new_desc']; ?></label>
                </dt>
                <dd class="opt">
                    <?php showEditor('marketing_activity_desc', $output['marketing_activity']['marketing_activity_desc_html'], '600px', '400px', 'visibility:hidden;', "true", $output['editor_multimedia']); ?>
                    <span class="err"></span>
                    <p class="notic"></p>
                </dd>
            </dl>
            <dl class="row">
                <dt class="tit">
                    <label for="marketing_activity_sort"><em>*</em><?php echo $lang['nc_sort']; ?></label>
                </dt>
                <dd class="opt">
                    <input type="text" id="marketing_activity_sort" name="marketing_activity_sort" class="input-txt"
                           value="<?php if ($output['marketing_activity']['marketing_activity_sort'] == '') { ?>255<?php } elseif ($output['marketing_activity']['marketing_activity_sort'] == '0') {
                               echo '0';
                           } else {
                               echo $output['marketing_activity']['marketing_activity_sort'];
                           } ?>">
                    <span class="err"></span>
                    <p class="notic"><?php echo $lang['activity_new_sort_tip1']; ?></p>
                </dd>
            </dl>
            <dl class="row">
                <dt class="tit">
                    <label for="marketing_activity_sort"><?php echo $lang['activity_openstate']; ?></label>
                </dt>
                <dd class="opt">
                    <div class="onoff">
                        <label for="marketing_activity_state1"
                               class="cb-enable <?php echo $output['marketing_activity']['marketing_activity_state'] == 1 ? 'selected' : ''; ?>"><?php echo $lang['activity_openstate_open']; ?></label>
                        <label for="marketing_activity_state0"
                               class="cb-disable <?php echo $output['marketing_activity']['marketing_activity_state'] == 0 ? 'selected' : ''; ?>"><?php echo $lang['activity_openstate_close']; ?></label>
                        <input id="marketing_activity_state1" name="marketing_activity_state"
                               <?php if ($output['marketing_activity']['marketing_activity_state'] == 1){ ?>checked="checked"<?php } ?>
                               value="1" type="radio">
                        <input id="marketing_activity_state0" name="marketing_activity_state"
                               <?php if ($output['marketing_activity']['marketing_activity_state'] == 0){ ?>checked="checked"<?php } ?>
                               value="0" type="radio">
                    </div>
                    <p class="notic"></p>
                </dd>
            </dl>
            <dl class="row">
                <dt class="tit">
                    <label for="marketing_activity_show"><?php echo $lang['activity_if_show']; ?></label>
                </dt>
                <dd class="opt">
                    <div class="onoff">
                        <label for="marketing_activity_show1"
                               class="cb-enable <?php echo $output['marketing_activity']['marketing_activity_show'] == 1 ? 'selected' : ''; ?>"><?php echo $lang['activity_showstate_open']; ?></label>
                        <label for="marketing_activity_show0"
                               class="cb-disable <?php echo $output['marketing_activity']['marketing_activity_show'] == 0 ? 'selected' : ''; ?>"><?php echo $lang['activity_showstate_close']; ?></label>
                        <input id="marketing_activity_show1"
                               name="marketing_activity_show" <?= (isset($output['marketing_activity']['marketing_activity_show']) && ($output['marketing_activity']['marketing_activity_show'] == 1)) ? 'checked="checked"' : '' ?>
                               value="1" type="radio">
                        <input id="marketing_activity_show0"
                               name="marketing_activity_show" <?= (isset($output['marketing_activity']['marketing_activity_show']) && ($output['marketing_activity']['marketing_activity_show'] == 0)) ? 'checked="checked"' : '' ?>
                               value="0" type="radio">
                    </div>
                    <p class="notic"></p>
                </dd>
            </dl>
            <div class="bot"><a href="JavaScript:void(0);" class="ncap-btn-big ncap-btn-green"
                                id="submitBtn"><?php echo $lang['nc_submit']; ?></a></div>
        </div>
    </form>
</div>
<script type="text/javascript" src="<?php echo ADMIN_RESOURCE_URL; ?>/js/jquery.nyroModal.js"></script>
<script src="<?php echo RESOURCE_SITE_URL; ?>/js/jquery-ui-timepicker-addon/jquery-ui-timepicker-addon.min.js"></script>
<link rel="stylesheet" type="text/css"
      href="<?php echo RESOURCE_SITE_URL; ?>/js/jquery-ui-timepicker-addon/jquery-ui-timepicker-addon.min.css"/>
<script>
    //按钮先执行验证再提交表单
    $(function () {
        $("#submitBtn").click(function () {
            if ($("#add_form").valid()) {
                $("#add_form").submit();
            }
        });
    });
    $(document).ready(function () {

        <?php if($output['if_alter'] === true):?>
        $("#marketing_activity_apply_start_date,#marketing_activity_apply_end_date,#marketing_activity_start_date,#marketing_activity_end_date").datetimepicker({controlType: 'select'});
        <?php endif;?>

        $('#marketing_activity_start_date').change(function(){
            $("#add_form").valid();
        });

        /**
         * 开始时间不能大于结束时间
         */
        jQuery.validator.methods.compareDate = function (value, element, param) {
            //补全yyyy-MM-dd HH:mm:ss格式，兼容ie，firefox
            var startDate = jQuery(param).val() + ":00";
            value = value + ":00";

            var date1 = new Date(Date.parse(startDate.replace(/-/g, "/")));
            var date2 = new Date(Date.parse(value.replace(/-/g, "/")));
            return date1 < date2;
        };
        jQuery.validator.methods.compareDate1 = function (value, element, param) {
            //补全yyyy-MM-dd HH:mm:ss格式，兼容ie，firefox
            var startDate = jQuery(param).val() + ":00";
            value = value + ":00";

            var date1 = new Date(Date.parse(startDate.replace(/-/g, "/")));
            var date2 = new Date(Date.parse(value.replace(/-/g, "/")));
            return date1 < date2;
        };

        $("#add_form").validate({
            errorPlacement: function (error, element) {
                var error_td = element.parents('dl').find('span.err');
                error_td.append(error);
            },
            rules: {
                marketing_activity_title: {
                    required: true
                },
                marketing_activity_apply_start_date: {
                    required: true,
                    date: false
                },
                marketing_activity_apply_end_date: {
                    required: true,
                    date: false,
                    compareDate: '#marketing_activity_apply_start_date'
                },
                marketing_activity_start_date: {
                    required: true,
                    date: false,
                    compareDate1: '#marketing_activity_apply_start_date'
                },
                marketing_activity_end_date: {
                    required: true,
                    date: false,
                    compareDate: '#marketing_activity_start_date',
                    compareDate1: '#marketing_activity_apply_end_date'
                },
                marketing_activity_banner: {
                    required: false,
                    accept: 'png|jpe?g|gif'
                },
                marketing_activity_sort: {
                    required: true,
                    min: 0,
                    max: 255
                },
                store_goods_limit: {
                    required: true,
                    min: 0,
                    max: 255
                }
            },
            messages: {
                marketing_activity_title: {
                    required: '<i class="fa fa-exclamation-circle"></i><?php echo $lang['activity_new_title_null'];?>'
                },
                marketing_activity_apply_start_date: {
                    required: '<i class="fa fa-exclamation-circle"></i><?php echo $lang['activity_new_applystartdate_null'];?>'
                },
                marketing_activity_apply_end_date: {
                    required: '<i class="fa fa-exclamation-circle"></i><?php echo $lang['activity_new_applyenddate_null'];?>',
                    compareDate: "报名截至时间必须大于报名开始时间!"
                },
                marketing_activity_start_date: {
                    required: '<i class="fa fa-exclamation-circle"></i><?php echo $lang['activity_new_startdate_null'];?>',
                    compareDate1: "报名开始时间不能大于等于活动开始时间"
                },
                marketing_activity_end_date: {
                    required: '<i class="fa fa-exclamation-circle"></i><?php echo $lang['activity_new_enddate_null'];?>',
                    compareDate: "结束日期必须大于开始日期!",
                    compareDate1: "报名结束时间不能大于等于活动结束时间"
                },
                marketing_activity_banner: {
                    required: '<i class="fa fa-exclamation-circle"></i><?php echo $lang['activity_new_banner_null'];?>',
                    accept: '<i class="fa fa-exclamation-circle"></i><?php echo $lang['activity_new_ing_wrong'];?>'
                },
                marketing_activity_sort: {
                    required: '<i class="fa fa-exclamation-circle"></i><?php echo $lang['activity_new_sort_null'];?>',
                    min: '<i class="fa fa-exclamation-circle"></i><?php echo $lang['activity_new_sort_minerror'];?>',
                    max: '<i class="fa fa-exclamation-circle"></i><?php echo $lang['activity_new_sort_maxerror'];?>'
                },
                store_goods_limit: {
                    required: '<i class="fa fa-exclamation-circle"></i><?php echo $lang['activity_new_storegoodslimit_null'];?>',
                    min: '<i class="fa fa-exclamation-circle"></i><?php echo $lang['activity_new_storegoodslimit_minerror'];?>',
                    max: '<i class="fa fa-exclamation-circle"></i><?php echo $lang['activity_new_storegoodslimit_maxerror'];?>'
                }
            }
        });
    });

    $(function () {
// 模拟活动页面横幅Banner上传input type='file'样式
        var textButton = "<input type='text' name='textfield' id='textfield1' class='type-file-text' /><input type='button' name='button' id='button1' value='选择上传...' class='type-file-button' />"
        $(textButton).insertBefore("#marketing_activity_banner");
        $("#marketing_activity_banner").change(function () {
            $("#textfield1").val($("#marketing_activity_banner").val());
        });
        $('.nyroModal').nyroModal();
    });
</script>